React = require('react')
Card = require('antd-mobile/lib/card')
# ListView = require('antd-mobile/lib/list-view')
Flex = require('antd-mobile/lib/flex')
Icon = require('antd-mobile/lib/icon')
Toast = require('antd-mobile/lib/toast')
SwipeAction = require('antd-mobile/lib/swipe-action')
RefreshControl = require('antd-mobile/lib/refresh-control')
{View,Image,Text,ScrollView,TouchableHighlight,StyleSheet,Navigator,ListView,TouchableOpacity} = require('react-native')
Dimensions = require('Dimensions')
{ width, height } = Dimensions.get('window')
{View} = require('react-native')
{fetchGetList,fetchRefreshList,fetchPilotConfirm,fetchPilotCancel} = require('../actions/page_yhyqr.js')
{connect} = require('react-redux')
_ = require('underscore')

backImg = require('../img/back.png')
searchIcon = require('../img/search_white.png')
basePage = require('../mixins/basePageNew.js')
DescInPage = require('./page_inattempDesc.js')
DescOutPage = require('./page_outDesc.js')
DescMovePage = require('./page_moveDesc.js')
List = require('antd-mobile/lib/list')

Page_Yhyqr = React.createClass
  mixins:[basePage]
  componentDidMount:->
    @initFetchData()
  rowClick:(rowData)->
    {navigator} = @props
    {CHDYNPLANID,CHPILOTAGESTATE} = rowData
    debugger
    switch CHPILOTAGESTATE
      when '1' then page = DescInPage
      when '2' then page = DescOutPage
      when '3' then page = DescMovePage
      else page = DescInPage
    setTimeout ->
      navigator.push
        component:page
        name:'inAttempDesc'
        title:'详情'
        params:
          id:CHDYNPLANID
    ,200
  renderRow:(rowData,sectionID,rowID,highlightRow)->
    # <SwipeAction onPress={@rowClick.bind(@,rowData)} key={rowData.INNO}>
    that = this
    debugger
    <SwipeAction
          style={{ backgroundColor: 'gray' }}
          autoClose:{true}
          right={[
            {
              text: '取消'
              onPress: ()->
                that.props.cancel rowData.CHDYNPLANID,rowData.CHPLANNO,that.props.token
              style: { backgroundColor: '#ddd', color: 'white' },
            },
            {
              text: '确认'
              onPress: ()->
                that.props.confirm rowData.CHDYNPLANID,rowData.CHPLANNO,that.props.token
              style: { backgroundColor: '#F4333C', color: 'white' }
            },
            {
              text: '查看'
              onPress: ()->
                debugger
                that.rowClick rowData
              style: { backgroundColor: 'blue', color: 'white' },
            },
          ]}>
      <View style={styles.row}>
        <View style={{flexDirection:'row'}}>
            <View style={{flex:1}}>
              <Text style=[styles.text,{fontWeight:'bold'}]>
                {"姓名：#{rowData.VCPILOTNAME}"}
              </Text>
            </View>
            <View style={{flex:1,justifyContent:'flex-end'}}>
              <Text style=[styles.text,{fontWeight:'bold'}]>
                {
                  if rowData.CHPILOTCALLFLAG is '0' then '未确认' else '确认'
                }
              </Text>
            </View>
        </View>
        <View style={{flexDirection:'row'}}>
          <Text style={styles.text}>
            {"#{rowData.VCVESCNAME}    #{rowData.VCVESENAME}"}
          </Text>
        </View>
        <View style={{flexDirection:'row'}}>
          <View style={{flex:1}}>
              <Text style={styles.text}>
                {"网上确认时间：#{@_processTime(rowData.DTSMSCOMFIRMTIME)}"}
              </Text>
            </View>
            <View style={{flex:1,justifyContent:'flex-end'}}>
              <Text style={styles.text}>
                {"短信确认时间：#{@_processTime(rowData.DTSMSSENDTIME)}"}
              </Text>
            </View>
        </View>
      </View>
    </SwipeAction>
  renderHeader:->
      <View style={{flexDirection:'row',flex:0,height:60,alignItems:'center', justifyContent:'center',backgroundColor:'#0066FF'}}>
        <View style={{flex:1,padding:10}}>
          <TouchableOpacity onPress={=>@props.navigator.pop()}>
            <Image source={backImg}  style={{height:30,width:30,resizeMode:'contain'}}/>
          </TouchableOpacity>
        </View>
        <View style={{flex:3,justifyContent:'center',alignItems:'center'}}>
          <Text style={{fontSize:20,color:'#ffffff'}}>引航员确认</Text>
        </View>
        <View style={{flex:1,alignItems:'flex-end',padding:10}}>
          <TouchableOpacity onPress={@_showActionSheet}>
          </TouchableOpacity>
        </View>
      </View>

styles = StyleSheet.create
  row:
    flexDirection:'column'
    justifyContent:'center'
    padding:10
    backgroundColor:'#F6F6F6'
  text:
    flex:1

mapStateToProps = (state)->
  list:state.page_yhyqr.list
  isLoading:state.page_yhyqr.isLoading
  completed:state.page_yhyqr.completed
  refreshing:state.page_yhyqr.refreshing
  connected:state.appState.connected
  token:state.userInfo.token
mapDispatchToProps = (dispatch,wonProps)->
  fetchGet:(token)->
    dispatch fetchGetList(token)
  fetchRefresh:(token)->
    dispatch fetchRefreshList(token)
  confirm:(planid,planno,token)->
    dispatch fetchPilotConfirm(planid,planno,token)
  cancel:(planid,planno,token)->
    dispatch fetchPilotCancel(planid,planno,token)
module.exports = connect(mapStateToProps,mapDispatchToProps)(Page_Yhyqr)
